package com.itboye.ihomebank.me.key;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;

import org.json.JSONException;
import org.json.JSONObject;

import android.bluetooth.BluetoothDevice;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.itboye.ihomebank.MainActivity;
import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.KeyAdapter;
import com.itboye.ihomebank.adapter.key.ItemMyKeyAdapter;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.KeyBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.custom.XListView;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.SPUtils;
import com.scaf.android.client.openapi.ScienerAPI;
import com.scaf.android.client.openapi.ScienerCallBack;
import com.scaf.android.client.service.Tools;

/**
 * 我的钥匙
 * 
 */
public class ActivityMyKey extends BaseOtherActivity implements Observer {
	ImageView close_icon;// 返回图片
	TextView add_shap_title_tv;// 标题

	XListView xlistview;

	KeyAdapter adapter;

	private List<Map<String, Object>> list;
	private ScienerAPI mScienerAPI;
	protected String TAG = "tag";
	private String uid;
	private UserPresenter userPresenter;

	public List<Map<String, Object>> Data() {
		list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("img", R.drawable.ic_launcher);
		map.put("name", "LOCK_566");
		map.put("img02", R.drawable.wuyefei);
		map.put("type", "普通用户");

		Map<String, Object> map02 = new HashMap<String, Object>();
		map02.put("img", R.drawable.ic_launcher);
		map02.put("name", "LOCK_566");
		map.put("img02", R.drawable.wuyefei);
		map02.put("type", "普通用户");
		list.add(map);
		list.add(map);
		return list;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;

		default:
			break;
		}
	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_my_key;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		// TODO Auto-generated method stub
		add_shap_title_tv.setText("我的智能锁");

		// adapter = new ItemMyKeyAdapter(ActivityMyKey.this, Data());
		// xlistview.setAdapter(adapter);
		uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
		userPresenter = new UserPresenter(this);
		if (uid != null) {
			if (!uid.equals("")) {
				// showProgressDialog("钥匙加载中", true);
				userPresenter.myKey("130");
			}
		}
		// mScienerAPI = new ScienerAPI(this, scienerCallBack);
		// mScienerAPI.setUp(this);
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	ScienerCallBack scienerCallBack = new ScienerCallBack() {

		@Override
		public void connectCallBack(BluetoothDevice device) {
			// handler.sendEmptyMessage(HANDLER_UPDATE_DISPLAY);
			// if (DeviceActivity.addLock) {
			// Log.d(TAG, "添加管理员");
			// DeviceActivity.addLock = false;
			// mScienerAPI.addAdmin();
			// } else {//开门
			// DoorKey doorKey = dbos.getDoorKeyFromLockName(device.getName());
			// if (doorKey == null)
			// return;
			// String unlockKey = doorKey.getLockKey();
			// String versionInfo = doorKey.getVersionInfo();
			// int lockFlagPos = doorKey.getLockFlagPos();
			// String adminPs = doorKey.getAdminPs();
			// byte[] encryKey = doorKey.getEncryKey();
			// byte[] encryIV = doorKey.getEncryIV();
			// if (doorKey.isAdmin()) {
			// Log.d(TAG, "管理员开锁");
			// Log.d(TAG, "管理员密码：" + adminPs);
			// if (doorKey.getVersionInfo().startsWith(VERSION_Va)) {
			// if (keyAdapter.lockcarOp == 1) {//开
			// mScienerAPI.unlockAdmin(versionInfo, adminPs, unlockKey,
			// lockFlagPos, encryKey, encryIV);
			// } else if (keyAdapter.lockcarOp == 0) {//关
			// mScienerAPI.lockAdmin(versionInfo, adminPs, unlockKey,
			// lockFlagPos, encryKey, encryIV);
			// }
			// } else {
			// if (doorKey.isResetEKey()) //重置电子钥匙
			// mScienerAPI.resetEKey(versionInfo, adminPs, unlockKey,
			// lockFlagPos + 1, encryKey, encryIV);
			// else {
			// // mScienerAPI.createPermanentPassword(versionInfo, adminPs,
			// lockFlagPos, encryKey, encryIV, "1234567");
			// // mScienerAPI.setOrQueryPara(versionInfo, adminPs, lockFlagPos,
			// encryKey, encryIV, "AT+CHECKPIN=1234567");
			// // mScienerAPI.fetchLockOpenRecord(versionInfo, adminPs,
			// lockFlagPos, encryKey, encryIV);
			// mScienerAPI.unlockAdmin(versionInfo, adminPs, unlockKey,
			// lockFlagPos, encryKey, encryIV);
			// }
			// }
			// } else {
			// String startDate = "0001010101";
			// String endDate = "9910101010";
			// if (doorKey.getStart_date() != 0) {
			// startDate = Tools.formateDateFromLong(doorKey.getStart_date(),
			// "yyMMddHHmm");
			// endDate = Tools.formateDateFromLong(doorKey.getEnd_date(),
			// "yyMMddHHmm");
			// }
			// Log.i(TAG, startDate + "--" + endDate);
			// Log.i(TAG, "unlockkey:" + unlockKey);
			//
			//
			// if (doorKey.getVersionInfo().startsWith(VERSION_Va)) {
			// if (keyAdapter.lockcarOp == 1) {//开
			// mScienerAPI.unlockEKey(versionInfo, unlockKey, startDate,
			// endDate, lockFlagPos, encryKey, encryIV);
			// } else if (keyAdapter.lockcarOp == 0) {//关
			// mScienerAPI.lockEKey(versionInfo, unlockKey, startDate, endDate,
			// lockFlagPos, encryKey, encryIV);
			// }
			// } else {
			// mScienerAPI.unlockEKey(versionInfo, unlockKey, startDate,
			// endDate, lockFlagPos, encryKey, encryIV);
			// }
			//
			// }
			// }
		}

		@Override
		public void disconnectCallBack() {
			// Toast.makeText(MainActivity.this, "ble disconnected",
			// Toast.LENGTH_LONG).show();
			// handler.sendEmptyMessage(HANDLER_UPDATE_DISPLAY);
			// if(DeviceActivity.getInstance() != null &&
			// DeviceActivity.getInstance().mHandler != null)
			// DeviceActivity.getInstance().mHandler.sendEmptyMessage(0);//刷新
			Log.d(TAG, "蓝牙已断开");
		}

		@Override
		public void createPasswordSuccessCallBack() {
			Log.i(TAG, "普通用户密码设置成功");
			// Toast.makeText(ActivityMyKey.this,
			// getString(R.string.ekey_user_setup_password_success),
			// Toast.LENGTH_LONG).show();
		}

		@Override
		public void clearAllPasswordSuccessCallBack() {
			// Toast.makeText(ActivityMyKey.this,
			// getString(R.string.clear_ekey_user_success),
			// Toast.LENGTH_LONG).show();
		}

		@Override
		public void fetchAllPasswordSuccessCallBack(String s) {
			// Toast.makeText(ActivityMyKey.this, "读取普通用户密码成功",
			// Toast.LENGTH_LONG).show();
			// Log.i(TAG, "普通用户键盘密码数据 : " + json);
			// Message msg = new Message();
			// msg.what = NormalUserPwdActivity.READ_PASSWORD_FINISHED;
			// msg.obj = json;
			// NormalUserPwdActivity.getInstance().handler.sendMessage(msg);
		}

		@Override
		public void deleteOnePasswordSuccessCallBack() {
			// Toast.makeText(ActivityMyKey.this, "删除单个普通用户密码成功",
			// Toast.LENGTH_LONG).show();
			// NormalUserPwdActivity.getInstance().handler.sendEmptyMessage(NormalUserPwdActivity.DELETE_SINGLE_PASSWORD_FINISHED);
		}

		@Override
		public void getLockVersionCallBack(int version) {
			Log.d(TAG, "锁版本：" + version);
			// Toast.makeText(ActivityMyKey.this,
			// getString(R.string.current_key_version) + version,
			// Toast.LENGTH_LONG).show();
		}

		@Override
		public void resetEKeySuccessCallBack(BluetoothDevice device,
				int lockFlagPos) {
			// Toast.makeText(MainActivity.this,
			// "reset lockFlagPos successed : " + lockFlagPos,
			// Toast.LENGTH_LONG).show();
			// final DoorKey doorKey =
			// dbos.getDoorKeyFromLockName(device.getName());
			// doorKey.setIsResetEKey(false);
			// doorKey.setLockFlagPos(lockFlagPos);
			// dbos.updateDoorKey(doorKey);
			// showProgress();
			// new Thread(new Runnable() {
			//
			// @Override
			// public void run() {
			// Looper.prepare();
			// String jsonValue = ResponseService.resetAllKey(access_token,
			// Config.APP_ID, doorKey.getRoomId(), doorKey.getLockFlagPos());
			// Log.d(TAG, "重置电子钥匙返回:" + jsonValue);
			// try {
			// JSONObject jsonObject = new JSONObject(jsonValue);
			// int errorCode = jsonObject.getInt("errcode");
			// String errorMsg = jsonObject.getString("errmsg");
			// String description = jsonObject.getString("description");
			// if(errorCode == 0) {
			// Toast.makeText(ActivityMyKey.this,
			// "lockFlagPos server syn successed", Toast.LENGTH_LONG).show();
			// } else {
			// Toast.makeText(ActivityMyKey.this, errorCode + " : " + errorMsg +
			// "(" + description + ")", Toast.LENGTH_LONG).show();
			// }
			// } catch (JSONException e) {
			// e.printStackTrace();
			// }
			// //只是做刷新用
			// handler.sendEmptyMessage(0);
			// Looper.loop();
			// }
			// }).start();
		}

		@Override
		public void unlockSuccessCallBack(BluetoothDevice device,
				int batteryCapacity) {
			// Log.d(TAG, getString(R.string.words_unlock_successed));
			// //batteryVolumn 返回-1 表示没有获取成功 或者 不支持电量
			// Log.d(TAG, "batteryCapacity:" + batteryCapacity);
			// Toast.makeText(ActivityMyKey.this,
			// R.string.words_unlock_successed, Toast.LENGTH_LONG).show();
			// Toast.makeText(MainActivity.this,
			// getString(R.string.batteryVolumn) + batteryCapacity,
			// Toast.LENGTH_LONG).show();

			// isLockcarConnecte = false;
			// KeyAdapter.lockcarOp = -1;
			//
			// DoorKey doorKey = dbos.getDoorKeyFromLockName(device.getName());
			// doorKey.setBatteryCapacity(batteryCapacity);
			// //车位锁使用
			// doorKey.setLockcarStatus(1);
			// dbos.updateDoorKey(doorKey);
			//
			// final String room_id = doorKey.getRoomId();
			// String versionInfo = doorKey.getVersionInfo();
			// int lockFlagPos = doorKey.getLockFlagPos();
			// byte[] encryKey = doorKey.getEncryKey();
			// byte[] encryIV = doorKey.getEncryIV();
			// String adminPs = doorKey.getAdminPs();
			//
			// switch (LockOperatorActivity.optionType) {
			// case LockOperatorActivity.OPTION_SET_KEYBOARD_PASSWORD:
			// Log.d(TAG, "设置键盘密码");
			// mScienerAPI.setAdminKeyBoardPassword(versionInfo,
			// LockOperatorActivity.keyboardPassword, adminPs, lockFlagPos,
			// encryKey, encryIV);
			// LockOperatorActivity.optionType = -1;
			// break;
			// case LockOperatorActivity.OPTION_CALIBRATE_TIME:
			// Log.d(TAG, "校准时间");
			// mScienerAPI.calibationTime(versionInfo, adminPs, lockFlagPos,
			// encryKey, encryIV);
			// LockOperatorActivity.optionType = -1;
			// break;
			// case LockOperatorActivity.OPTION_SET_NORMAL_USER_PASSWORD:
			// Log.d(TAG, "设置用户键盘密码");
			// int keyboardPwdType =
			// NormalUserPasswordFragmentActivity.keyboardPwdType;
			// String password = NormalUserPasswordFragmentActivity.password;
			// int useTimes = NormalUserPasswordFragmentActivity.useTimes;
			// String startDate =
			// Tools.formateDateFromLong(NormalUserPasswordFragmentActivity.startDate,
			// "yyMMddHHmm");
			// String endDate =
			// Tools.formateDateFromLong(NormalUserPasswordFragmentActivity.endDate,
			// "yyMMddHHmm");
			// mScienerAPI.setNormalUserKeyboardPassword(versionInfo, adminPs,
			// lockFlagPos, encryKey, encryIV, keyboardPwdType, password,
			// useTimes, startDate, endDate);
			// LockOperatorActivity.optionType = -1;
			// break;
			// case LockOperatorActivity.OPTION_CLEAR_NORMAL_USER_PASSWORD:
			// Log.d(TAG, "清除用户键盘密码");
			// mScienerAPI.clearNormalUserKeyboardPassword(versionInfo, adminPs,
			// lockFlagPos, encryKey, encryIV);
			// LockOperatorActivity.optionType = -1;
			// break;
			// case LockOperatorActivity.OPTION_READ_NORMAL_USER_PASSWORD:
			// Log.d(TAG, "读取用户键盘密码");
			// mScienerAPI.readNormalUserKeyboardPassword(versionInfo, adminPs,
			// lockFlagPos, encryKey, encryIV);
			// LockOperatorActivity.optionType = -1;
			// break;
			// case LockOperatorActivity.OPTION_SYN_USER_PASSWORD:
			// LockOperatorActivity.optionType = -1;
			// Log.d(TAG, "同步用户密码");
			// // handler.sendEmptyMessage(SHOW_PROGRESS_DIALGO);
			// //同步用户密码时，请确保手机联网并且绑定管理员成功
			// mScienerAPI.synUserPassword(Config.APP_ID, access_token,
			// versionInfo, room_id, adminPs, lockFlagPos,
			// LockOperatorActivity.efficientPwds);
			// break;
			// case LockOperatorActivity.OPTION_SET_DELETE_PASSWORD:
			// mScienerAPI.setDeletePassword(versionInfo, adminPs, lockFlagPos,
			// LockOperatorActivity.keyboardPassword, encryKey, encryIV);
			// LockOperatorActivity.optionType = -1;
			// break;
			// default:
			// break;
			// }
			//
			// new Thread(new Runnable() {
			//
			// @Override
			// public void run() {
			// String jsonValue = rs.uploadUnlockRecord(access_token,
			// Config.APP_ID, room_id, 1);
			// Log.d(TAG, "上传开锁记录返回:" + jsonValue);
			// }
			// }).start();

		}

		@Override
		public void lockSuccessCallBack(BluetoothDevice device,
				int batteryCapacity) {
			// isLockcarConnecte = false;
			// KeyAdapter.lockcarOp = -1;
			// DoorKey doorKey =
			// dbos.getDoorKeyFromLockMac(device.getAddress());
			// doorKey.setLockcarStatus(0);
			// dbos.updateDoorKey(doorKey);
			Toast.makeText(ActivityMyKey.this, "Lock successed",
					Toast.LENGTH_LONG).show();
		}

		@Override
		public void setAdminKeyboardPasswordSuccessCallBack(
				BluetoothDevice device, String keyboardPassword) {
			// Toast.makeText(getApplicationContext(),
			// R.string.words_set_pwd_successfully, Toast.LENGTH_LONG).show();
			Log.i(TAG, "键盘密码设置成功，密码为：" + keyboardPassword);
			// DoorKey doorKey = dbos.getDoorKeyFromLockName(device.getName());
			// doorKey.setKeyboardPassword(keyboardPassword);
			// dbos.updateDoorKey(doorKey);
			// currentDoorKey = doorKey;
			// if(LockOperatorActivity.getInstance() != null &&
			// LockOperatorActivity.getInstance().handler != null)
			// LockOperatorActivity.getInstance().handler.sendEmptyMessage(0);//刷新
		}

		@Override
		public void foundDeviceCallBack(final BluetoothDevice device, int rssi,
				boolean enable) {
			// Log.d(TAG, "发现设备：" + device.getName());
			if (device == null || device.getName() == null)
				return;
			// DeviceActivity deviceInstance = DeviceActivity.getInstance();
			// if (deviceInstance != null && deviceInstance.mHandler != null) {
			// Message msg = new Message();
			// msg.what = DeviceActivity.HANDLER_FOUND_DEVICE;
			// msg.obj = device;
			// deviceInstance.mHandler.sendMessage(msg);
			// }
			// //判断本地是否已经存在锁
			// DoorKey doorKey = dbos.getDoorKeyFromLockName(device.getName());
			// // DoorKey doorKey =
			// dbos.getDoorKeyFromLockMac(device.getAddress());
			// if (doorKey != null) {
			// //手动模式不进行连接
			// if (isAppOn == false && doorKey.getUnlockMode() == MODE_MANUAL) {
			// Log.d(TAG, "maual not to connect");
			// return;
			// }
			// boolean flag = true;
			// if (doorKey.getVersionInfo().startsWith(VERSION_Va)) {
			// if (isLockcarConnecte)
			// flag = true;
			// else
			// flag = false;
			// }
			// if (flag)
			// mScienerAPI.connect(device);
			// }
		}

		@Override
		public void calibationTimeSuccessCallBack() {
			// Log.d(TAG, getString(R.string.words_calbrate_time_successed));
			// Toast.makeText(getApplicationContext(),
			// R.string.words_calbrate_time_successed,
			// Toast.LENGTH_LONG).show();
		}

		@Override
		public void errorCallBack(int errcode) {
			Log.d(TAG, "返回的错误码：" + errcode);
			// String errMsg = null;
			// switch (errcode) {
			// case ScienerAPI.LOCK_ADMIN_EXIST:
			// errMsg = getString(R.string.error_lock_admin_exist);
			// break;
			// case ScienerAPI.LOCK_INVALID_USER_TIME:
			// errMsg = getString(R.string.error_lock_invalid_user_time);
			// break;
			// case ScienerAPI.LOCK_ADMIN_CHECK_ERROR:
			// errMsg = getString(R.string.error_lock_admin_check_failed);
			// break;
			// case ScienerAPI.LOCK_SET_ADMIN_SUPER_PWD_FAILED:
			// errMsg =
			// getString(R.string.error_lock_set_admin_super_pwd_failed);
			// break;
			// case ScienerAPI.LOCK_UNLOCK_FAIL:
			// errMsg = getString(R.string.error_lock_unlock_faile);
			// break;
			// case ScienerAPI.LOCK_CALIBATION_TIME_FAIL:
			// errMsg = getString(R.string.error_lock_calibation_time_faile);
			// break;
			// case ScienerAPI.LOCK_CRC_CHECK_FAIL:
			// errMsg = getString(R.string.error_lock_CRC_check_faile);
			// break;
			// case ScienerAPI.LOCK_INVALID_UNLOCK_FLAG:
			// errMsg = getString(R.string.error_lock_invalid_unlock_flag);
			// break;
			// case ScienerAPI.LOCK_IS_NOT_SETTING_MODE:
			// errMsg = getString(R.string.error_lock_is_not_setting_mode);
			// break;
			// case ScienerAPI.LOCK_NO_POWER:
			// errMsg = getString(R.string.error_lock_no_power);
			// break;
			// case ScienerAPI.LOCK_LOCKID_ERROR:
			// errMsg = getString(R.string.error_invalid_lockid);
			// break;
			// case ScienerAPI.LOCK_GET_AESKEY_FAILED:
			// errMsg = "Get AES key failed";
			// break;
			// case ScienerAPI.LOCK_AES_PARSE_ERROR:
			// errMsg = "AES parse error";
			// break;
			// case ScienerAPI.LOCK_PWD_LEN_ERROR:
			// errMsg = "Passoword length error";
			// break;
			// case ScienerAPI.LOCK_SET_DELETE_PWD_FAILED:
			// errMsg = "Failed to set delete password";
			// break;
			// case ScienerAPI.LOCK_SET_PWD_ERROR://三代锁
			// errMsg = "Failed to set password";
			// break;
			// case ScienerAPI.KEY_INVALID:
			// errMsg = "Invalid key";
			// break;
			// }
			Toast.makeText(ActivityMyKey.this, errcode + "", Toast.LENGTH_LONG)
					.show();
		}

		@Override
		public void addAdminSuccessCallBack(final String versionInfo,
				final BluetoothDevice device, final String adminPs,
				final String unlockKey, final byte[] encryKey,
				final byte[] encryIV) {
			Log.i(TAG, "管理员添加成功");
			// final int lockFlagPos = 0;
			// new Thread(new Runnable() {
			//
			// @Override
			// public void run() {
			// Log.d(TAG, "versionInfo:" + versionInfo);
			// String[] versionInfos = versionInfo.split("\\.");
			// String jsonData = rs.bindingAdmin(access_token, Config.APP_ID,
			// device.getName(), unlockKey, device.getAddress(), //开锁密码保存方式
			// versionInfos[0], versionInfos[1], versionInfos[2],
			// versionInfos[3], versionInfos[4], encryKey);
			// Log.d(TAG, "绑定管理员返回结果：" + jsonData);
			// JSONObject jsonObject;
			// String room_id = "";
			// String key_id = "";
			// try {
			// jsonObject = new JSONObject(jsonData);
			// if (jsonObject.has("room_id")) {
			// room_id = jsonObject.getString("room_id");
			// }
			// if (jsonObject.has("key_id")) {
			// key_id = jsonObject.getString("key_id");
			// }
			// Log.d(TAG, "MAC : " + device.getAddress());
			// DoorKey doorKey = new DoorKey(openid, versionInfo, true, 2,
			// room_id, adminPs, unlockKey, device.getName(),
			// device.getAddress(), null, key_id, lockFlagPos, -1, encryKey,
			// encryIV, 0, 0, 0, MODE_MANUAL, device.getName(), "", false,
			// false, 1);
			// dbos.saveDoorKey(doorKey);
			// DeviceActivity.getInstance().finish();
			// } catch (JSONException e) {
			// Log.i(TAG, "json_EXCEPTION : " + e);
			// e.printStackTrace();
			// }
			// Log.i(TAG, "成功绑定的房间id:" + room_id);
			// Log.i(TAG, "成功绑定的key_id:" + key_id);
			// }
			// }).start();
			// 管理员添加成功，继续发送校准时间指令，校准锁时间
			// mScienerAPI.calibationTime(versionInfo, adminPs, lockFlagPos,
			// encryIV, encryIV);
		}

		@Override
		public void synPwdProgressCallBack(int progress) {
			// Toast.makeText(ActivityMyKey.this,
			// getString(R.string.words_progress) + progress,
			// Toast.LENGTH_SHORT).show();
			// progressDialog.setProgress(progress);
		}

		@Override
		public void synPwdSuccessCallBack(BluetoothDevice device, String pwdJson) {
			// DoorKey doorkey =
			// dbos.getDoorKeyFromLockMac(device.getAddress());
			// if (doorkey.getVersionInfo().startsWith(VERSION_V4)) {
			// Message msg = new Message();
			// msg.what = HANDLER_UPLOAD_KEYBOARD_PWD;
			// msg.obj = pwdJson;
			// handler.sendMessage(msg);
			// } else if (doorkey.getVersionInfo().startsWith(VERSION_V2S)) {
			// Toast.makeText(MainActivity.this,
			// getString(R.string.async_keyboard_password_success),
			// Toast.LENGTH_LONG).show();
			// String roomId = doorkey.getRoomId();
			// try {
			// if (dbos.getPwdsByRoomid(Integer.valueOf(roomId)) == null)
			// dbos.savePwds(roomId, pwdJson);
			// else
			// dbos.updatePwds(roomId, pwdJson);
			// } catch (JSONException e) {
			// e.printStackTrace();
			// }
			// }
		}

		//
		@Override
		public void setDeletePasswordSuccessCallBack(BluetoothDevice device,
				String deletePwd) {
			// Toast.makeText(ActivityMyKey.this,
			// R.string.words_set_delete_pwd_successfully,
			// Toast.LENGTH_LONG).show();
			// Log.i(TAG, "删除密码设置成功，密码为：" + deletePwd);
			// DoorKey doorKey = dbos.getDoorKeyFromLockName(device.getName());
			// doorKey.setDeletePwd(deletePwd);
			// dbos.updateDoorKey(doorKey);
			// currentDoorKey = doorKey;
			// if(LockOperatorActivity.getInstance() != null &&
			// LockOperatorActivity.getInstance().handler != null)
			// LockOperatorActivity.getInstance().handler.sendEmptyMessage(0);//刷新
		}

		@Override
		public void resetLockSuccessCallBack() {
			Toast.makeText(ActivityMyKey.this, "resetLockSuccessCallBack",
					Toast.LENGTH_LONG).show();
		}

		@Override
		public void fetchLockOpenRecordSuccessCallBack(String openRecdList) {
			Toast.makeText(ActivityMyKey.this,
					"fetchLockOpenRecordSuccessCallBack : " + openRecdList,
					Toast.LENGTH_LONG).show();
		}

		@Override
		public void setOrQueryParaSuccessCallBack(String para) {
			Toast.makeText(ActivityMyKey.this, "para : " + para,
					Toast.LENGTH_LONG).show();
		}
	};

	private KeyBean keyBeans;

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);

		keyBeans = (KeyBean) entity.getData();
		if (keyBeans != null) {
			if (keyBeans.getList().size() >= 1) {
				// img_nodata.setVisibility(View.GONE);
				xlistview.setVisibility(View.VISIBLE);
				adapter = new KeyAdapter(ActivityMyKey.this,
						keyBeans.getList(), R.layout.item_my_key);
				xlistview.setAdapter(adapter);
				// for (int i = 0; i < 10; i++) {
				// KeyModel bean = new KeyModel();
				// bean.setName(i + "");
				// bean.setUrl("http://b.hiphotos.baidu.com/album/s%3D1600%3Bq%3D90/sign=4f04be8ab8014a90853e42bb99470263/b8389b504fc2d562d426d1d5e61190ef76c66cdf.jpg?v=tbs");
				// arrayListHouse.add(bean);
				// }
				// adapter.notifyDataSetChanged();
			} else {
				// img_nodata.setVisibility(View.VISIBLE);
				xlistview.setVisibility(View.GONE);
			}
		}

	}
}
